package com.zhb86.kuaipai;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.superyee.commonlib.utils.StatusBarUtil;
import com.zhb86.kuaipai.ui.main.ATMain;

public class ATSplash extends AppCompatActivity {

    private View mImageView;
    private boolean isFinished = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        if (!isTaskRoot()
                && getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
                && getIntent().getAction() != null
                && getIntent().getAction().equals(Intent.ACTION_MAIN)) {

            finish();
            return;
        }
        StatusBarUtil.transparencyStatusBar(this);
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        mImageView = findViewById(R.id.imageView);
        mImageView.postDelayed(initRunnable, 300);
    }

    @Override
    protected void onStop() {
        mImageView.removeCallbacks(initRunnable);
        isFinished = true;
        super.onStop();
        finish();
    }

    Runnable initRunnable = new Runnable() {
        @Override
        public void run() {
            if (isFinishing() || isFinished) {
                return;
            }
            Intent intent = new Intent(ATSplash.this, ATMain.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            finish();
        }
    };

}
